package cate.game.admin.menu.chat;

import cate.common.table.d.GDChat;
import cate.game.GameBody;
import cate.game.admin.menu.MenuSetup;
import cate.game.chat.ChatFacade;

public class ChatMenu extends MenuSetup {

    public ChatMenu(GameBody gameBody) {
        super("聊天");

        reg(gameBody, "清除聊天数据", 0, "", (role, params) -> {
            role.getChat().forbidReason = "";
            role.getChat().lastChatTime = System.currentTimeMillis();
            role.getChat().forbidUntil = System.currentTimeMillis();
        });

        reg(gameBody, "持续发送聊天", 1, "每秒x条(默认1)",
                (role, params) -> {
            int timesSec = params == null || params.isEmpty() ? 1 : Integer.parseInt(params.get(0));
            new Thread(() -> {
                int idx=0;
                for(int i=0; i<60; ++i){
                    for(int j=0;j<timesSec;++j){
                        idx++;
                        ChatFacade.sendPublicFromClient(role, GDChat.Channel.WORLD,0, "今天天气不错" + idx, null);
                    }
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }).start();
        });
    }
}
